﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPCarousel.SPCarousel
{
    [ToolboxItemAttribute(false)]
    public class SPCarousel : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SPCarousel/SPCarousel/SPCarouselUserControl.ascx";


        private bool _redirectLink;
        private bool _textlinks;

        private int _autoScroll;
        private bool _vertical;

        #region Required
        private int _itemWidth = 75;
        private int _itemHeight = 75;
        private int _paddingX = 10;
        private int _paddingY = 10;
        private string _listname;

        private bool _showArrows;
        private int _numberOfIcons;
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Show Arrows"),
        WebDescription("Show or Hide Arrows"), Category("SPCarousel Required")]
        public bool ShowArrows
        {
            get { return _showArrows; }
            set { _showArrows = value; }
        }
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Number Of Icons"),
        WebDescription("Number of icons visable at one time"),
        Category("SPCarousel Required")]
        public int NumberOfIcons
        {
            get { return _numberOfIcons; }
            set { _numberOfIcons = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         WebDisplayName("List Name"),
         WebDescription("Name of the list that you want to pull pictures from"),
         Category("SPCarousel Required")]
        public string Listname
        {
            get { return _listname; }
            set { _listname = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         WebDisplayName("Margin X-Axis"),
         WebDescription("sets the Padding along the X axis"),
         Category("SPCarousel Required")]
        public int PaddingX
        {
            get { return _paddingX; }
            set { _paddingX = value; }
        }

        
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Item Width"),
        WebDescription("sets the width of the item "),
        Category("SPCarousel Required")]
        public int ItemWidth
        {
            get { return _itemWidth; }
            set { _itemWidth = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Item Height"),
        WebDescription("sets the Height of the item "),
        Category("SPCarousel Required")]
        public int ItemHeight
        {
            get { return _itemHeight; }
            set { _itemHeight = value; }
        }

        #endregion
        #region Styling
        private string _leftArrowURL = "/_layouts/SPCarousel/skins/tango/next-horizontal.png";
        private string _rightArrowURL = "/_layouts/SPCarousel/skins/tango/prev-horizontal.png";
        private string _leftArrowVerticalURL = "/_layouts/SPCarousel/skins/tango/prev-vertical.png";
        private string _rightArrowVerticalURL = "/_layouts/SPCarousel/skins/tango/next-vertical.png";
        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         WebDisplayName("Right Vertical Arrow URL"),
         WebDescription("URl for Right Vertical arrow image"), 
         Category("SPCarousel Styling"),
         DefaultValue("/_layouts/SPCarousel/skins/tango/prev-vertical.png")]
        public string RightArrowVerticalURL
        {
            get { return _rightArrowVerticalURL; }
            set { _rightArrowVerticalURL = value; }
        }
        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         WebDisplayName("Left Vertical Arrow URL"),
         WebDescription("URl for left  Vertical arrow image"),
         Category("SPCarousel Styling"),
         DefaultValue("/_layouts/SPCarousel/skins/tango/next-vertical.png")]
        public string LeftArrowVerticalURL
        {
            get { return _leftArrowVerticalURL; }
            set { _leftArrowVerticalURL = value; }
        }

        private string _arrowStyleSheet;

        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(false),
         WebDisplayName("Arrows Stylesheet"),
         WebDescription("Style"),
         Category("SPCarousel Styling")]
        public string ArrowStyleSheet
        {
            get { return _arrowStyleSheet; }
            set { _arrowStyleSheet = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Left Arrow URL"),
        WebDescription("URl for left arrow image"),
        Category("SPCarousel Styling"),
        DefaultValue("/_layouts/SPCarousel/skins/tango/next-horizontal.png")]
        public string LeftArrowURL
        {
            get { return _leftArrowURL; }
            set { _leftArrowURL = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Right Arrow URL"),
        WebDescription("URl for Right arrow image"),
        Category("SPCarousel Styling"),
        DefaultValue("/_layouts/SPCarousel/skins/tango/prev-horizontal.png")]
        public string RightArrowURL
        {
            get { return _rightArrowURL; }
            set { _rightArrowURL = value; }
        }

        #region stylesheet
        private string _styleSheet = @".jcarousel-skin-tango .jcarousel-container 
{   margin:0 auto; -moz-border-radius: 10px;    -webkit-border-radius: 10px;    border-radius: 10px;    background: #FF;
}
.jcarousel-skin-tango .jcarousel-direction-rtl 
{	direction: rtl;
}
img 
{border:0px !important; text-decoration: none;
}
a.div{
margin:0 auto;
text-align:center;
}
a 
{border:0px !important; text-decoration: none;
}
a:hover 
{border:0px !important; text-decoration: none;
}
a :visited
{border:0px !important; text-decoration: none;
}
.jcarousel-skin-tango .jcarousel-clip 
{    overflow: hidden;
}
.jcarousel-skin-tango .jcarousel-item-horizontal 
{	margin-left: 0;    margin-right: 10px;
}
.jcarousel-skin-tango .jcarousel-direction-rtl .jcarousel-item-horizontal 
{	margin-left: 10px;    margin-right: 0;
}
.jcarousel-skin-tango .jcarousel-item-vertical 
{    margin-bottom: 10px;
}
.jcarousel-skin-tango .jcarousel-item-placeholder 
{    background: #fff;    color: #000;
}

";
        [Personalizable(PersonalizationScope.Shared),
 WebBrowsable(true),
WebDisplayName("Stylesheet"),
WebDescription("Style"),
Category("SPCarousel Styling")]
        public string Stylesheet
        {
            get { return _styleSheet; }
            set { _styleSheet = value; }
        }
        #endregion
        #endregion
        #region Behaiviour

        public enum Wrap { both, left, right };

        private Wrap _wrap;
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Wrap Type"),
        WebDescription("Name of the list that you want to pull pictures from"),
        Category("SPCarousel Behaviour")]
        public Wrap WrapCarousel
        {
            get { return _wrap; }
            set { _wrap = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Auto Scroll"),
        WebDescription("Wether the slider should autoscroll"),
        Category("SPCarousel Behaviour")]
        public int AutoScroll
        {
            get { return _autoScroll; }
            set { _autoScroll = value; }
        }
        #endregion
        #region webpart Properties



        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(false),
        WebDisplayName("Vertical"),
        WebDescription("Vertical or Horizontal Display"),
        Category("SPCarousel Styling")]
        public bool Vertical
        {
            get { return _vertical; }
            set { _vertical = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(false),
        WebDisplayName("RedirectLink"),
        WebDescription("Should the link redirect the user or make a blow up image"),
        Category("Advanced")]
        public bool RedirectLink
        {
            get { return _redirectLink; }
            set { _redirectLink = value; }
        }

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("TextLinks"),
        WebDescription("Should links be in a textual format or encapsulate the image"),
        Category("SPCarousel Styling")]
        public bool Textlinks
        {
            get { return _textlinks; }
            set { _textlinks = value; }
        }

        #endregion

        protected override void CreateChildControls()
        {
            SPWeb web = SPContext.Current.Web;
            Control control = Page.LoadControl(_ascxPath);
            Controls.Add(control);
        }

        //public override EditorPartCollection CreateEditorParts()
        //{
        //    var editor = new ListPicker
        //    {
        //        ID = ID + "_Editor",
        //        Title = "SPCarousel List Picker"
        //    };
        //    return new EditorPartCollection(new EditorPart[] { editor });
        //}
    }
}

